home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / vdigit.zip / VRMOD.ASM < prev    next >
Assembly Source File  |  1989-06-24  |  17KB  |  731 lines

  1. page 58,132
  2. .286c
  3. .MODEL LARGE
  4.  
  5. ;**********************************************************************
  6. ;*                                                                    *
  7. ;*                             Equates                                *
  8. ;*                                                                    *
  9. ;**********************************************************************
  10.  
  11. tccount        equ    72    ;reload count to produce 16572 Hz
  12. countmax_18hz    equ    910    ;ratio of new timer rate to old rate
  13.  
  14. tcaddrc        equ    43h    ;timer/counter control register address
  15. tcaddrd        equ    40h    ;timer/counter data register zero
  16.  
  17. tcmode        equ    34h    ;mode control byte for timer/counter
  18.  
  19. ppiaddr        equ    61h    ;programmable peripheral interface address
  20.  
  21. ;**********************************************************************
  22. ;*                                                                    *
  23. ;*                             Macros                                 *
  24. ;*                                                                    *
  25. ;**********************************************************************
  26.  
  27. ljz    macro    dest
  28.     local    skip
  29.     jnz    skip
  30.     jmp    dest
  31. skip:
  32.     endm
  33.  
  34. ;**********************************************************************
  35. ;*                                                                    *
  36. ;*                         Global variables                           *
  37. ;*                                                                    *
  38. ;**********************************************************************
  39.  
  40. .DATA
  41.         even        ;don't put these on an odd boundary
  42.  
  43. blockaddr    dd    0    ;beginning of memory block
  44. blocksize    dd    0    ;size of memory block
  45. blockend    dd    0    ;last address of memory block + 1
  46. currentaddr    dd    0    ;pointer to current record position in memory
  47. datacount    dd    0    ;number of data bytes already recorded
  48. fwrtaddr    dd    0    ;address of next byte to be written to disk
  49. fwrtcount    dd    0    ;number of bytes already written to disk
  50.  
  51. goflag        dw    0    ;indicates whether recording is in progress
  52. fileflag    dw    0    ;indicates whether data is written to a file
  53. filehandle    dw    0    ;handle of file to receive voice data
  54. hookedflag    dw    0    ;indicates whether the interrupt is hooked
  55. countfor_18hz    dw    0    ;counter to determine when to call BIOS
  56. comaddr        dw    0    ;the address of the COM port
  57.  
  58. comlist        dw    3FEh    ;needed addresses of all COM ports
  59.         dw    2FEh
  60.         dw    3EEh
  61.         dw    2EEh
  62.  
  63. shiftcount    db    0    ;current bit position within byte
  64.  
  65. ;**********************************************************************
  66. ;*                                                                    *
  67. ;*                               Code                                 *
  68. ;*                                                                    *
  69. ;**********************************************************************
  70.  
  71. .CODE
  72.  
  73. bios_timer_routine    dd    0    ;we keep this in the code segment
  74.                     ; for access through the CS register
  75.                     ; since the other segment registers
  76.                     ; will contain unknown values when
  77.                     ; this is needed
  78.  
  79.     assume    ds:DGROUP
  80.  
  81. ;**********************************************************************
  82. ;*             Speed up the timer tick and set "goflag"               *
  83. ;**********************************************************************
  84.  
  85. startvoice    proc    near
  86.  
  87.     pushf
  88.     cli
  89.     mov    al,tcmode
  90.     out    tcaddrc,al
  91.     mov    ax,tccount
  92.     out    tcaddrd,al
  93.     mov    al,ah
  94.     out    tcaddrd,al
  95.     mov    shiftcount,0
  96.     mov    countfor_18hz,countmax_18hz
  97.     mov    goflag,1
  98.     popf
  99.     ret
  100.  
  101. startvoice    endp
  102.  
  103. ;**********************************************************************
  104. ;*         Slow the timer tick to normal and clear "goflag"           *
  105. ;**********************************************************************
  106.  
  107. stopvoice    proc    near
  108.  
  109.     pushf
  110.     cli
  111.     mov    al,tcmode
  112.     out    tcaddrc,al
  113.     mov    al,0
  114.     out    tcaddrd,al
  115.     out    tcaddrd,al
  116.     mov    goflag,0
  117.     popf
  118.     ret
  119.  
  120. stopvoice    endp
  121.  
  122. ;**********************************************************************
  123. ;*                   Interrupt service routine                        *
  124. ;**********************************************************************
  125.  
  126. timer_tick    proc    far
  127.  
  128.     push    ds
  129.     push    bx
  130.     push    es
  131.     push    ax
  132.     push    cx
  133.     push    dx
  134.  
  135.     mov    ax,DGROUP
  136.     mov    ds,ax
  137.  
  138.     cmp    goflag,0
  139.     je    chain_exit
  140.  
  141.     les    bx,currentaddr
  142.     mov    ah,es:[bx]
  143.     mov    dx,comaddr
  144.     in    al,dx
  145.     rcl    al,4
  146.     rcl    ah,1
  147.     mov    es:[bx],ah
  148.  
  149.     inc    shiftcount
  150.     and    shiftcount,07h
  151.     jnz    exit_decide
  152.  
  153.     mov    ax,es
  154.     inc    bx
  155.     jnz    check_wrap
  156.     add    ax,1000h
  157. check_wrap:
  158.     cmp    bx,word ptr blockend
  159.     jne    save_cur_addr
  160.     cmp    ax,word ptr blockend+2
  161.     jne    save_cur_addr
  162.     mov    bx,word ptr blockaddr
  163.     mov    ax,word ptr blockaddr+2
  164. save_cur_addr:
  165.     mov    word ptr currentaddr,bx
  166.     mov    word ptr currentaddr+2,ax
  167.     add    word ptr datacount,1
  168.     adc    word ptr datacount+2,0
  169.  
  170. exit_decide:
  171.     dec    countfor_18hz
  172.     jnz    nochain_exit
  173.     mov    countfor_18hz,countmax_18hz
  174.  
  175. chain_exit:
  176.     pop    dx
  177.     pop    cx
  178.     pop    ax
  179.     pop    es
  180.     pop    bx
  181.     pop    ds
  182.     jmp    cs:bios_timer_routine
  183.  
  184. nochain_exit:
  185.     mov    al,20h
  186.     out    20h,al
  187.     pop    dx
  188.     pop    cx
  189.     pop    ax
  190.     pop    es
  191.     pop    bx
  192.     pop    ds
  193.     iret
  194.  
  195. timer_tick    endp
  196.  
  197. ;**********************************************************************
  198. ;*                   Initialization procedure                         *
  199. ;**********************************************************************
  200.  
  201. ;This routine should be called exactly one time before any of the other
  202. ; routines in this package are called. It takes no parameters, but returns
  203. ; a value indicating success or failure as follows:
  204.  
  205. ;Return value        Meaning
  206. ;------------        -------
  207. ;     0              success
  208. ;     1              voice package already initialized
  209. ;     2              wrong CPU, won't run on 8088 or 8086
  210.  
  211.     public    RVOICE_INIT
  212.  
  213. RVOICE_INIT    proc    far
  214.  
  215.     push    sp
  216.     pop    ax
  217.     cmp    ax,sp
  218.     je    vi_test
  219.     mov    ax,2
  220.     ret
  221.  
  222. vi_test:
  223.     cmp    hookedflag,0
  224.     je    vi_hook
  225.     mov    ax,1
  226.     ret
  227.  
  228. vi_hook:
  229.     enter    0,0
  230.     push    si
  231.     push    di
  232.  
  233.     push    ds
  234.     lea    dx,RVOICE_CBREAK
  235.     mov    ax,seg RVOICE_CBREAK
  236.     mov    ds,ax
  237.     mov    ax,2523h
  238.     int    21h
  239.     pop    ds
  240.  
  241.     push    ds
  242.     mov    ax,3508h
  243.     int    21h
  244.     mov    word ptr cs:bios_timer_routine,bx
  245.     mov    word ptr cs:bios_timer_routine+2,es
  246.     lea    dx,timer_tick
  247.     mov    ax,seg timer_tick
  248.     mov    ds,ax
  249.     mov    ax,2508h
  250.     int    21h
  251.     pop    ds
  252.  
  253.     pop    di
  254.     pop    si
  255.     mov    hookedflag,1
  256.     sub    ax,ax
  257.     leave
  258.     ret
  259.  
  260. RVOICE_INIT    endp
  261.  
  262. ;**********************************************************************
  263. ;*                      Cleanup procedure                             *
  264. ;**********************************************************************
  265.  
  266. ;This will restore the interrupt 8 vector to its original state. This
  267. ; routine MUST be called before the main program exits to DOS, unless:
  268. ; (a) the program has never called RVOICE_INIT, or (b) the program is
  269. ; becoming memory-resident.
  270.  
  271. ;There are no parameters. The return values are 0 for success or 1 if
  272. ; the interrupt vector was not in fact hooked.
  273.  
  274.     public    RVOICE_CLEANUP
  275.  
  276. RVOICE_CLEANUP    proc    far
  277.  
  278.     cmp    hookedflag,1
  279.     je    vc_unhook
  280.     mov    ax,1
  281.     ret
  282.  
  283. vc_unhook:
  284.     enter    0,0
  285.     push    si
  286.     push    di
  287.     call    stopvoice
  288.     push    ds
  289.     lds    dx,cs:bios_timer_routine
  290.     mov    ax,2508h
  291.     int    21h
  292.     pop    ds
  293.     pop    di
  294.     pop    si
  295.     mov    hookedflag,0
  296.     sub    ax,ax
  297.     leave
  298.     ret
  299.  
  300. RVOICE_CLEANUP    endp
  301.  
  302. ;**********************************************************************
  303. ;*                Vector restore for Control-Break                    *
  304. ;**********************************************************************
  305.  
  306.     public    RVOICE_CBREAK
  307.  
  308. RVOICE_CBREAK    proc    far
  309.  
  310.     pusha
  311.     push    ds
  312.     push    es
  313.  
  314.     mov    ax,DGROUP
  315.     mov    ds,ax
  316.     call    stopvoice
  317.     call    RVOICE_CLEANUP
  318.  
  319.     pop    es
  320.     pop    ds
  321.     popa
  322.     stc
  323.     ret
  324.  
  325. RVOICE_CBREAK    endp
  326.  
  327. ;**********************************************************************
  328. ;*                "File write catch-up" procedure                     *
  329. ;**********************************************************************
  330.  
  331. ;This must be called frequently from the main program if file writing is
  332. ; being used and the length of the data to be recorded is longer than the
  333. ; length of the memory block. The routine checks the progress of the
  334. ; address pointer in use by the interrupt service routine